package com.cpr.ams.service.impl;

import com.cpr.ams.bean.Prince;
import com.cpr.ams.bean.Room;
import com.cpr.ams.bean.RoomExample;
import com.cpr.ams.bean.extend.RoomExtend;
import com.cpr.ams.mapper.PrinceMapper;
import com.cpr.ams.mapper.RoomMapper;
import com.cpr.ams.mapper.extend.RoomExtendMapper;
import com.cpr.ams.service.IRoomService;
import com.jacky.base.utils.PageVM;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements IRoomService {
    @Autowired
    private RoomMapper roomMapper;
    @Autowired
    private RoomExtendMapper roomExtendMapper;
    @Autowired
    private PrinceMapper princeMapper;
    @Override
    public void saveOrUpdateRoom(Room room) {
        if (room.getRoomId()!=null){
            roomMapper.updateByPrimaryKeySelective(room);
        }else {
            roomMapper.insert(room);
        }
    }

    @Override
    public void deleteByIdRoom(int id) {
           roomMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageVM<RoomExtend> query(Integer page, Integer pageSize, Integer roomId, String status, Integer type) {
        List<RoomExtend> list=roomExtendMapper.query(page,pageSize,roomId,status,type);
        long total =roomExtendMapper.count(roomId,status,type);
        return new PageVM<>(page, pageSize, total, list);
    }

    @Override
    public RoomExtend queryById(int id) {
        return roomExtendMapper.queryById(id);
    }

    @Override
    public void saveOrUpdatePrince(Prince prince) {
        if (prince.getId()!=null){
            princeMapper.updateByPrimaryKeySelective(prince);
        }else {
            princeMapper.insert(prince);
        }
    }

    @Override
    public void deleteByIdPrince(int id) {
           princeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Prince> queryPrinces() {
        List<Prince> list= princeMapper.selectByExample(null);
        return list;
    }

    @Override
    public void updateById(Room room) {
        roomMapper.updateByPrimaryKeySelective(room);
    }

    @Override
    public List<Room> findAll() {
        return roomMapper.selectByExample(new RoomExample());
    }
}
